package test.swing;

/**
 * @Description TODO(这里用一句话描述这个类的作用)
 *
 * @author liuqinghua
 * @date 2023-8-30
 */

import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.util.Base64;

import org.knowm.xchart.BitmapEncoder;
import org.knowm.xchart.BitmapEncoder.BitmapFormat;
import org.knowm.xchart.PieChart;
import org.knowm.xchart.PieChartBuilder;
import org.knowm.xchart.SwingWrapper;

public class BarChart01 {

    public static void main(String[] args) throws IOException {
        PieChart chart = new PieChartBuilder().width(800).height(600).title("饼状图演示").build();

        // 创建Chart
        Color[] sliceColors = new Color[] { new Color(224, 68, 14), new Color(230, 105, 62), new Color(236, 143, 110),
                new Color(243, 180, 159), new Color(246, 199, 182) };
        chart.getStyler().setSeriesColors(sliceColors);

        // 添加数据源
        chart.addSeries("Gold", 24);
        chart.addSeries("Silver", 21);
        chart.addSeries("Platinum", 39);
        chart.addSeries("Copper", 17);
        chart.addSeries("Zinc", 40);

        BitmapEncoder.saveBitmap(chart, "d:/poi/img", BitmapFormat.PNG);
        String imgStr = "data:image/png;base64,"
                + Base64.getEncoder().encodeToString(BitmapEncoder.getBitmapBytes(chart, BitmapFormat.PNG));
        System.out.println(imgStr);
        File tmp = new File("d:/poi/img.txt");

        // 进行展示
        new SwingWrapper<PieChart>(chart).displayChart();
    }

}